// pages/xuanzeyinhangk/xuanzeyinhangk.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: []
  },
  // 选择
  fixyinhangka(e) {
    let that = this;
    if (this.endTime - this.startTime < 350) {
      var pages = getCurrentPages();
      var currPage = pages[pages.length - 1];
      var prevPage = pages[pages.length - 2]; //获取上一个页面
      prevPage.setData({ //修改上一个页面的变量
        yinhangkainfo: that.data.list[e.currentTarget.dataset.listindex],
        personname: that.data.list[e.currentTarget.dataset.listindex].accname,
      })
      wx.navigateBack({
        delta: -1
      })
    }
  },
  // 手指按下
  handleTouchStart: function(e) {
    this.startTime = e.timeStamp;
  },
  //手指离开
  handleTouchEnd: function(e) {
    this.endTime = e.timeStamp;
  },

  //长按删除微信
  changan(e) {
    let listindex = e.currentTarget.dataset.listindex
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定解绑该银行卡",
      success(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/setting/page/jiebangyinhangk/jiebangyinhangk?info=' + JSON.stringify(that.data.list[e.currentTarget.dataset.listindex]),

          })
        } else if (res.cancel) {}
      }
    });
  },
  // 获取列表
  getinfolist() {
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "getBindAccountList",
        // shopId: wx.getStorageSync('shopId'),
        userId: wx.getStorageSync('userId'),
        acctype: 1
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        console.log(res)
        if (res.data.result == 1) {
          setTimeout(function() {
            wx.hideLoading()
          }, 0)
          setTimeout(function() {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          let list = res.data.bindList
          for (var i in list) {
            list[i].accouentWeihao = list[i].account.substring(list[i].account.length - 4)
          }
          that.setData({
            list: list
          })
          setTimeout(function() {
            wx.hideLoading()
          }, 0)
        }
      }
    });
  },
  bangding() {
    let that = this
    let list = that.data.list
    if (list.length < 3) {
      wx.navigateTo({
        url: '/pages/setting/page/bangdingyinhangk/bangdingyinhangk',
        // url: '/pages/bangdingyinhangk/bangdingyinhangk',
      })
    } else {
      wx.showToast({
        title: '最多绑定3个银行账户',
        icon: 'none'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this
    setTimeout(function() {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.getinfolist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: '众商联采',
      path: "/pages/login/login", // 路径，传递参数到指定页面。
      // imageUrl:'../../../images/logo/LOGO.png'
      imageUrl: app.globalData.logo
    }
  }
})